#include <stdio.h>
#include <stdlib.h>

#define ENV         "USER1"
#define OVERWRITE   1

int main()
{
    char *old_user, *new_user;

    old_user = getenv(ENV);
    if (NULL == old_user)
    {
        printf(ENV " not found!\n");
    }
    else
    {
        printf("before set, " ENV " is %s\n", old_user);
    }
    new_user = "xuzhi";
    if ((setenv(ENV, new_user, OVERWRITE)) < 0)
    {
        printf("set USER error!\n");
        exit(0);
    }

    if (fork() == 0)    /* fork child process*/
    {
        printf("In child process:\n");
    }

    new_user = getenv(ENV);
    if (NULL == new_user)
    {
        printf(ENV " not found!\n");
    }
    else
    {
        printf("after set, " ENV " is %s\n", new_user);
    }

    return 0;
}
